import {Component} from '@angular/core';
import {NavController, NavParams} from 'ionic-angular';

import {Backend} from '../../providers/backend';

import {TabMy} from './tab-my';
import {LoginPage} from './tab-my-login';
@Component({
  templateUrl: 'build/pages/tab-my/tab-my-registration.html'
})
export class Registration {

  static get parameters() {
    return [[NavController], [NavParams], [Backend]];
  }
  constructor(nav, params, backend) {
    this.nav = nav;
    this.params = params;
    this.backend = backend;
    this.firstname;
    this.lastname;
    this.email;
    this.nickname;
    this.password;
    this.confirmpassword;
    this.wrongmessage;
    this.wrongmessage1;
    this.wrongmessage2;
  }
  login() {
    this.nav.pop(LoginPage);
  }
  // testEmail() {
  //   var filter = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
  //   if (!filter.test(this.email)) {
  //     this.wrongmessage1 = this.wrongmessage = '*请输入正确邮箱地址';
  //   } else {
  //     this.wrongmessage = undefined;
  //     this.wrongmessage1 = undefined;
  //   }
  // }

  // testpaw() {
  //   var paw = /^(?=.{6,16}$)(?![0-9]+$)(?!.*(.).*\1)[0-9a-zA-Z]+$/;
  //   if (!paw.test(this.password)) {
  //     this.wrongmessage2 = this.wrongmessage = '*请输入6-16位不完全相同的数字和字母';
  //   } else {
  //     this.wrongmessage = undefined;
  //     this.wrongmessage2 = undefined;
  //   }
  // }
  // register() {
  //   if (typeof (this.wrongmessage1) === 'string') {
  //     this.wrongmessage = '*请输入正确邮箱地址';
  //   } else if (typeof (this.wrongmessage2) === 'string') {
  //     this.wrongmessage = '*请输入6-16位不完全相同的数字和字母';
  //   } else if (this.password !== this.confirmpassword) {
  //     this.wrongmessage = '*两次输入密码不相同';
  //   } else if (typeof (this.firstname) === 'undefined' || typeof (this.lastname) === 'undefined' || typeof (this.email) === 'undefined' || typeof (this.nickname) === 'undefined') {
  //     this.wrongmessage = '*所填信息不能为空';
  //   } else {
  //     if ((this.password === this.confirmpassword) && typeof (this.firstname) === 'string' && typeof (this.lastname) === 'string' && typeof (this.email) === 'string' && typeof (this.nickname) === 'string' && typeof (this.password) === 'string' && typeof (this.wrongmessage) === 'undefined' && typeof (this.wrongmessage1) === 'undefined') {
  //       this.nav.push(TabMy, { id: 1 });
  //     }
  //   }
  // }
  register() {
    this.backend.register(this.firstname, this.lastname, this.email, this.nickname, this.password, this.confirmpassword)
      .then(result => {
        this.suvery = result;
        console.log(this.suvery);
        if(this.suvery.status_id == 200){
          this.nav.push(LoginPage);
        }else{
          this.wrongmessage=this.suvery.info ;
        }
      });
  }
}
